﻿@{
    ViewBag.Title = "值班计划";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}
@model IList<Wicresoft.UnifyShow2.Portal.Models.DutyPlanCalendarEventModel>
<link href="../../Content/fullcalendar.css" rel="stylesheet" />
<link href="../../Content/fullcalendar.print.css" rel="stylesheet" media='print' />
<script src="../../Scripts/fullcalendar.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        var msg1 = $("#ViewMsg").val();
        if (msg1 != "") {
            alert(msg1);
        }
    });
    $(function () {
        $("form").submit(function () {
            var myfile = $("#FileUpload").val();
            if (myfile == "") {
                alert("请选择需上传的文件！")
                return false;
            }
            else {
                var filename = myfile.replace(/.*(\/|\\)/, "");
                var fileExt = (/[.]/.exec(filename)) ? /[^.]+$/.exec(filename.toLowerCase()) : '';
                if (fileExt == "xlsx" || fileExt == "xls") {
                    if (confirm("确认上传该值班计划！"))
                        return true;
                    else
                        return false;
                }
                else{
                    alert("上传的文件格式不正确，请重新选择！");
                    return false;
                }
            }
        });

        var date = new Date();
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();

        var calendar = $('#calendar').fullCalendar({
            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            selectable: true,
            select: function (start, end, allDay) {
                var today = new Date();
                today.setHours(0, 0, 0, 0);
                var nextDay = new Date();
                nextDay.setDate(nextDay.getDate() + 1);
                nextDay.setHours(0, 0, 0, 0);

                if (end <= today) {
                    return false;
                }

                if (start < nextDay) {
                    start = nextDay;
                }

                var startdt = $.fullCalendar.formatDate(start, "yyyy/MM/dd");
                var enddt = $.fullCalendar.formatDate(end, "yyyy/MM/dd");
                //var keeper = $.fullCalendar.title;
                //var phone = $.fullCalendar.phone;
                var url = "@Url.Action("Create", "DutyPlan")";
                //url += "?start=" + startdt + "&end=" + enddt + "&allDay=" + allDay + "&keeper=" + keeper + "&phone=" + phone;
                url += "?start=" + startdt + "&end=" + enddt + "&allDay=" + allDay;
                $("#dutyPlan").dialog({
                    href: url
                });
                $("#dutyPlan").dialog("open");

                calendar.fullCalendar('unselect');
            },
            monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月',
 '八月', '九月', '十月', '十一月', '十二月'],
            monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
            dayNames: ['星期日', '星期一', '星期二', '星期三',
 '星期四', '星期五', '星期六'],
            dayNamesShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],

            buttonText: {
                prev: '上月',
                next: '下月',
                today: '今天',
                month: '月',
                week: '周',
                day: '日'
            },
            events: function (start, end, callback) {//生成日历
                //alert(calendar.fullCalendar('getDate'));
                var events = [];
                $.ajax({
                    'url': "/dutyPlan/GetPlanData",
                    'data': {
                        start: $.fullCalendar.formatDate(start, "yyyy/MM/dd"),
                        end: $.fullCalendar.formatDate(end, "yyyy/MM/dd")
                    },
                    'dataType': 'json',
                    'type': 'post',
                    'error': function (data) {
                        alert("保存失败");
                        return false;
                    },
                    'success': function (doc) {

                        $(doc).each(function (i) {
                            events.push({
                                title: doc[i].title,
                                start: doc[i].start,
                                end: doc[i].end,
                                allDay: true,
                                className: 'dutyplan',
                                editable: doc[i].editable
                            });
                        });
                        callback(events);//
                    }
                });

            }
        });
        $("#dutyPlan").dialog({
            closed: true,
            width: 560,
            height: 320,
            modal: true,
            buttons: [{
                text: '保存',
                iconCls: 'icon-ok',
                handler: function () {
                    if ($("#WatchKeeper").val() != "") {
                        $.post("@Url.Action("Create", "DutyPlan")", $("#dutyPlanForm").serialize(),
                                        function () {
                                            alert("操作成功！");
                                            $("#dutyPlan").dialog("close");
                                            $('#calendar').fullCalendar('refetchEvents');
                                        });
                    }
                    else {
                        alert("值班人员不能为空！");
                    }
                }
            },
            {
                text: '删除',
                iconCls: 'icon-cut',
                handler: function () {
                    $.post("@Url.Action("Delete", "DutyPlan")", $("#dutyPlanForm").serialize(),
                                        function () {
                                            alert("操作成功！");
                                            $("#dutyPlan").dialog("close");
                                            $('#calendar').fullCalendar('refetchEvents');
                                        });
                }
            },
            {
                text: '取消',
                iconCls: 'icon-cancel',
                handler: function () { $('#dutyPlan').dialog("close"); }
            }]
        });

        $('.foot').css({ top: document.documentElement.scrollHeight - $('.foot').height() });
    });

</script>
<style type="text/css">
    .dutyplan { margin-top: 20px; text-align: center; font-size: 14px; font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif; }
    .main_left .left_menu { border: 1px solid #92a9bb; height: 750px; }
    #calendar { width: 800px; margin: 10px auto; }
</style>

<div class="index_lr">
    <div class="index_lrA_title ui-icons">
        <h3>值班计划管理</h3>
    </div>
    <div class="index_pt_bg">
        @using (Html.BeginForm("Index", "DutyPlan", FormMethod.Post, new { enctype = "multipart/form-data" }))
        {
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tbody>
                <tr>
                    <td class="tdName" width="300px">
                        点击"<a href="http://selfservice.fj-tobacco.com:8098/DutyPlanDoc/Exp/DutyData.xls"><b><span style="font-style:italic;">下载</span></b></a>"值班计划模板
                    </td>
                    <td class="tdData" width="300px">
                        <input type="file" name="FileUpload" id="FileUpload" class=":required"  />
                    </td>
                    <td>
                        <input type="submit" class="Button1 ui-icons" id="Submit" value="上传" title="确认上传" />
                    </td>
                    <td>
                        <input type="text" id="ViewMsg" name="ViewMsg" value="@ViewBag.Msg" style="visibility:hidden" hidden="hidden" />
                    </td>
                </tr>
            </tbody>
        </table>
        }
    </div>
    <div class="index_pt_bg">
        <div id='calendar'></div>
        <div id="dutyPlan" class="easyui-dialog" title="值班计划"></div>
    </div>
</div>




